package inits

import (
	"fmt"
	"golang.org/x/crypto/bcrypt"
	"srv/basic/global"
	"srv/handler/model"
)

func InitSuperAdmin() {
	var count int64
	global.DB.Model(&model.Admin{}).Where("role = ?", 1).Count(&count)
	if count == 0 {
		hashedPwd, _ := bcrypt.GenerateFromPassword([]byte("123456"), bcrypt.DefaultCost)
		superAdmin := &model.Admin{
			Username: "superadmin",
			Password: string(hashedPwd),
			Role:     1,
		}
		global.DB.Create(&superAdmin)
		fmt.Println("已创建超级管理员: superadmin / 123456")
	}
}

func InitSuperAdmin1() {
	var admin model.Admin
	global.DB.Model(&model.Admin{}).Where("role = ?", 1).First(&admin)
	if admin.ID == 0 {
		hashedPwd, _ := bcrypt.GenerateFromPassword([]byte("123456"), bcrypt.DefaultCost)
		superAdmin := &model.Admin{
			Username: "superadmin",
			Password: string(hashedPwd),
			Role:     1,
		}
		global.DB.Create(&superAdmin)
		fmt.Println("已创建超级管理员: superadmin / 123456")
	}
}
